package com.jdk.thread.oschina;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

public class TestThreadPoolMain {

	public static void main(String[] args) {
		// 设置配置
		ThreadPoolConfig config = ThreadPoolConfig.getInstance();
		config.setCorePoolSize(2);
		config.setMaxNumPoolSize(3);
		config.setKeepAliveTime(5);
		config.setUnit(TimeUnit.SECONDS);
		// 将队列设小，会抛异常
		config.setWorkQueue(new ArrayBlockingQueue<Runnable>(5));
		config.setHandler(new MyRejectedExecutionHandler());
		// 线程池工厂
		ThreadPoolFactory factory = ThreadPoolFactory.getInstance(config);

		for (int i = 0; i < 100; i++) {
			factory.addTask(new ThreadTask("线程--" + i));
		}
		System.out.println("i add is over!-------------------");

		factory.closePool();
	}
}
